Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase Integration and Confidence Filtering #35

Merged
merged 6 commits into from
Mar 6, 2025
Merged

Firebase Integration and Confidence Filtering #35

merged 6 commits into from
Mar 6, 2025

Conversation

aajain2
Copy link
Contributor

@aajain2 aajain2 commented Mar 5, 2025

Firebase Integration and Confidence Filtering

♻️ Current situation & Problem

Currently, the CoughSync app can detect coughs using sound analysis, but these detections are not persisted to any backend service. This means that cough data is lost when the app is closed, preventing long-term tracking and analysis. Additionally, the current implementation accepts all detected coughs regardless of confidence level, leading to potential false positives. This PR implements the Firebase integration for cough data storage, fixes dependency injection issues in the CoughDetectionViewModel, and adds confidence filtering to ensure only high-quality cough detections are recorded.

⚙️ Release Notes

Key features:

  • Cough detections are now automatically stored in Firebase via the CoughSyncStandard

  • Only moderate-confidence coughs (>50%) are recorded to reduce false positives

  • Cough model enhanced to include confidence score information

  • Fixed dependency injection issues in view models to properly access the -

  • CoughSyncStandard
    Example of Firebase integration and confidence filtering:
    if displayName == "Coughs" && confidence > 0.5 { // Only record if confidence > 50%
    let cough = Cough(timestamp: Date(), confidence: confidence)
    coughCollection.addCough(cough)

    // Store the cough in Firebase
    Task {
    await standard.add(cough: cough)
    }
    }

📚 Documentation

This PR introduces Firebase integration for persistent storage of cough detection data. When a cough is detected with sufficient confidence (>50%), it is both stored locally in the CoughCollection and sent to Firebase through the CoughSyncStandard interface. The Cough model has been enhanced to include a confidence property that stores the machine learning model's confidence level for each detection. This value ranges from 0.0 to 1.0, with higher values indicating greater confidence. By filtering coughs at the 0.5 threshold, we significantly reduce false positives while maintaining detection sensitivity. The dependency injection architecture has been improved to properly access the CoughSyncStandard from the SwiftUI environment. This follows the Spezi framework's recommended patterns for dependency injection, initializing view models when their containing views appear to ensure environment values are available. All code changes are documented with inline comments explaining the purpose of each component and the rationale behind design decisions, in accordance with the Spezi Documentation Guide.

✅ Testing

Testing verified Firebase storage, confidence filtering effectiveness, and dependency injection fixes. Manual testing was used due to audio input simulation challenges.

📝 Code of Conduct & Contributing Guidelines

By submitting creating this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

Copy link

codecov bot commented Mar 5, 2025

Codecov Report

Attention: Patch coverage is 31.25000% with 55 lines in your changes missing coverage. Please review.

Project coverage is 52.12%. Comparing base (5238df6) to head (0cfbd51).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
CoughSync/CoughView/CoughModelView.swift 0.00% 27 Missing ⚠️
CoughSync/CoughSyncStandard.swift 0.00% 18 Missing ⚠️
...hSync/CoughDetection/CoughDetectionViewModel.swift 30.00% 7 Missing ⚠️
CoughSync/CoughDetection/CoughClass.swift 0.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #35      +/-   ##
==========================================
- Coverage   52.66%   52.12%   -0.53%     
==========================================
  Files          38       38              
  Lines        1396     1443      +47     
==========================================
+ Hits          735      752      +17     
- Misses        661      691      +30     
Files with missing lines Coverage Δ
CoughSync/Dashboard/Dashboard.swift 100.00% <100.00%> (+4.35%) ⬆️
CoughSync/CoughDetection/CoughClass.swift 22.73% <0.00%> (-2.27%) ⬇️
...hSync/CoughDetection/CoughDetectionViewModel.swift 18.34% <30.00%> (+2.95%) ⬆️
CoughSync/CoughSyncStandard.swift 50.00% <0.00%> (-10.00%) ⬇️
CoughSync/CoughView/CoughModelView.swift 0.00% <0.00%> (-1.51%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5238df6...0cfbd51. Read the comment docs.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -80,4 +95,9 @@ class CoughDetectionViewModel {
identifiedSound = nil
coughAnalysisManager.stopCoughDetection()
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this used? If not necessary, please remove.

}

// For batch saving multiple coughs at once (optional)
func add(coughs: [Cough]) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not used now, please remove.

@@ -13,51 +13,63 @@
//

import SwiftUI
import Spezi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix this error

@State private var previousCoughCount: Int = 0

init(presentingAccount: Binding<Bool>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix this error.

Copy link
Contributor

@MiguelAFH MiguelAFH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work. Just make sure to fix the errors.

@MiguelAFH MiguelAFH self-requested a review March 6, 2025 02:59
Copy link
Contributor

@MiguelAFH MiguelAFH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bugs fixed now

@aajain2 aajain2 enabled auto-merge (squash) March 6, 2025 03:06
@aajain2 aajain2 merged commit f3cae1e into main Mar 6, 2025
9 of 10 checks passed
@aajain2 aajain2 deleted the firestore branch March 6, 2025 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants